package v1

import (
	"gitee.com/buddyxiao/ginblog/middleware"
	"gitee.com/buddyxiao/ginblog/model"
	"gitee.com/buddyxiao/ginblog/utils/errmsg"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Login(ctx *gin.Context) {
	var data model.User
	_ = ctx.ShouldBindJSON(&data)
	code := model.CheckLogin(data.Username,data.Password)
	var token string
	if code == errmsg.SUCCESS {
		token,code = middleware.SetToken(data.Username)
	}
	ctx.JSON(http.StatusOK,gin.H{
		"status": code,
		"msg": errmsg.GetErrMsg(code),
		"token": token,
	})
}
